#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// DrawLib compiler
// Author: mc_kibel
// This is application for PC, it's NOT ELF!
// Compile it with correct #define directive, then run .exe 
// (or just press F9 in Code::Blocks)
// then DrawLib for your phone will be generated immediately.
// Porting for other phones: just open any .h file and port addresses.
// DrawLibs are needed for Deskbar older than 3.32 and ClearBass older than 2.2


//#define C510_R1FA035
//#define C510_R1HA035
#define C901_R1GA028
//#define C905_R1FA035
//#define J105_R1HA035
//#define W705_R1GA026
//#define W715_R1GA030
//#define W995_R1GA026

#ifdef C901_R1GA028
#define path "DLib_C901_R1GA028/DrawLib.bin"
#define command "mkdir DLib_C901_R1GA028"
#include "Target/C901_R1GA028.h"
#endif

#ifdef C510_R1HA035
#define path "DLib_C510_R1HA035/DrawLib.bin"
#define command "mkdir DLib_C510_R1HA035"
#include "Target/C510_R1HA035.h"
#endif

#ifdef C905_R1FA035
#define path "DLib_C905_R1FA035/DrawLib.bin"
#define command "mkdir DLib_C905_R1FA035"
#include "Target/C905_R1FA035.h"
#endif

#ifdef J105_R1HA035
#define path "DLib_J105_R1HA035/DrawLib.bin"
#define command "mkdir DLib_J105_R1HA035"
#include "Target/J105_R1HA035.h"
#endif

#ifdef W705_R1GA026
#define path "DLib_W705_R1GA026/DrawLib.bin"
#define command "mkdir DLib_W705_R1GA026"
#include "Target/W705_R1GA026.h"
#endif

#ifdef W715_R1GA030
#define path "DLib_W715_R1GA030/DrawLib.bin"
#define command "mkdir DLib_W715_R1GA030"
#include "Target/W715_R1GA030.h"
#endif

#ifdef W995_R1GA026
#define path "DLib_W995_R1GA026/DrawLib.bin"
#define command "mkdir DLib_W995_R1GA026"
#include "Target/W995_R1GA026.h"
#endif

#ifdef C510_R1FA035
#define path "DLib_C510_R1FA035/DrawLib.bin"
#define command "mkdir DLib_C510_R1FA035"
#include "Target/C510_R1FA035.h"
#endif

int addr_table[] = {OSE_CreateInstance,GC_CreateObject,UI_IMAGE_MANAGER_IID,UI_IMAGE_MANAGER_GUID};
char *addr_names[] = {"OSE_CreateInstance","GC_CreateObject","UI_IMAGE_MANAGER_IID","UI_IMAGE_MANAGER_GUID"};

void get_pmodel (char *dest,char *src)
{
    int i;
    int len1 = strlen("DLib_A123_R1AA000");
    int len2 = strlen ("A123_R1AA000");
    int diff = len1 - len2;
    for (i = diff ; i < len1 ; i++) dest[i-diff] = src[i];
}

int main (void)
{
    int i,j;
    char pmodel[32];
    memset(pmodel,0,32);
    get_pmodel(pmodel,path);
    printf ("DrawLib Creator\n(c) mc_kibel\nGoing to create DrawLib for %s...\n",pmodel);
    system (command);
    FILE * f = fopen (path,"wb");
    for (j = 0 ; j < 4 ; j++)
    {
        for (i = 4 ; i > 0 ; i--) fputc(addr_table[j]>>(8*(i-1)),f);
        printf("%s addr:        0x%X \n",addr_names[j],addr_table[j]);
    }
    fclose (f);
    return 0;
}
